package com.kummuna.ui;


import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.kummuna.R;
import com.kummuna.util.image.ImageLoader;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class WaterLeakDetail extends Activity {

	GoogleMap map;
	TextView txtlatlng;
	TextView txtTopic;
	TextView txtDetail;
	TextView txtTime;
	ImageView img1;
	LatLng latLng;
	String idFromWaterLeakTabMain;
	String topicFromWaterLeakTabMain;
	String detailFromWaterLeakTabMain;
	String latitudeFromWaterLeakTabMain;
	String longtitudeFromWaterLeakTabMain;
    String distanceFromDetectShortPath;
    String dateFromDetectShortPath;
    String urltitudeFromDetectShortPath;
    
    public ImageLoader imageLoader;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.water_leak_detail);

		// get intent
		Intent itn = getIntent();
		idFromWaterLeakTabMain = itn.getStringExtra("id");
		topicFromWaterLeakTabMain = itn.getStringExtra("topic");
		detailFromWaterLeakTabMain = itn.getStringExtra("detail");
		latitudeFromWaterLeakTabMain = itn.getStringExtra("latitude");
		longtitudeFromWaterLeakTabMain = itn.getStringExtra("longtitude");
        distanceFromDetectShortPath = itn.getStringExtra("distance");
        dateFromDetectShortPath = itn.getStringExtra("date");
        urltitudeFromDetectShortPath = itn.getStringExtra("url");

		String latlong = latitudeFromWaterLeakTabMain + ","
				+ longtitudeFromWaterLeakTabMain;

		txtlatlng = (TextView) findViewById(R.id.txtlatlong);
		txtlatlng.setText(latlong);

		// call map
		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
				.getMap();
		map.getUiSettings().setZoomControlsEnabled(false);
		map.getUiSettings().setScrollGesturesEnabled(false);

		latLng = new LatLng(Double.parseDouble(latitudeFromWaterLeakTabMain),
				Double.parseDouble(longtitudeFromWaterLeakTabMain));

		MarkerOptions markerOptions = new MarkerOptions();
		markerOptions.position(latLng);
		markerOptions.title(latLng.latitude + " : " + latLng.longitude);

		CameraPosition cameraPosition = new CameraPosition.Builder()
				.target(latLng).zoom(15).bearing(-30).tilt(90).build();

		// map.animateCamera(CameraUpdateFactory.newLatLng(latLng));
		map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

		// Adding marker on the GoogleMap
		map.addMarker(markerOptions);
		imageLoader = new ImageLoader(WaterLeakDetail.this
				.getApplicationContext());

		// set up topic
		txtTopic = (TextView) findViewById(R.id.topic);
		txtDetail = (TextView) findViewById(R.id.detail);
		txtTime = (TextView) findViewById(R.id.time);
		img1 = (ImageView) findViewById(R.id.list_image1);

		txtTopic.setText(topicFromWaterLeakTabMain);
		txtDetail.setText(detailFromWaterLeakTabMain);
		txtTime.setText(dateFromDetectShortPath);
		imageLoader.DisplayImage(urltitudeFromDetectShortPath, img1);

	}

	public void nextpage(View view) {

		Intent mapIntent = new Intent(WaterLeakDetail.this, RouteMap.class);
		mapIntent.putExtra("id", idFromWaterLeakTabMain);
		mapIntent.putExtra("topic", topicFromWaterLeakTabMain);
		mapIntent.putExtra("detail", detailFromWaterLeakTabMain);
		mapIntent.putExtra("latitude", latitudeFromWaterLeakTabMain);
		mapIntent.putExtra("longtitude", longtitudeFromWaterLeakTabMain);
		mapIntent.putExtra("time", dateFromDetectShortPath);
		startActivity(mapIntent);
	}
	
	public void btnShowImage(View view){
		Intent mapIntent = new Intent(WaterLeakDetail.this, Carousel.class);
		startActivity(mapIntent);
	}

}
